<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        // let s1 = Symbol("sex");
        // let s2 = Symbol("like");

        // let obj = {
        //     name:"老王",
        //     age:18,
        //     [s1]:"男",
        //     [s2]:["篮球","足球","王者"]
        // }

        // 只能获取到传统的属性
        // for(let item in obj){
        //     console.log(item,obj[item]);
        // }

        // 获取到symbol属性
        // let arr = Object.getOwnPropertySymbols(obj);

        // console.log(arr);

        // console.log(obj[arr[0]]);


        // 二次加工对象下的 for of
        let s1 = Symbol("sex");
        let s2 = Symbol("like");

        let obj = {
            name: "老王",
            age: 18,
            [s1]: "男",
            [s2]: ["篮球", "足球", "王者"]
        }

        Object.prototype[Symbol.iterator] = function () {
            // console.log(this); //obj
            let keys = Object.keys(this);
            // console.log(keys); // ['name', 'age']
            let sKeys = Object.getOwnPropertySymbols(this);
            // console.log(sKeys); //[Symbol(sex), Symbol(like)]
            
            let allArr = [...keys, ...sKeys];
            // console.log(allArr); //['name', 'age', Symbol(sex), Symbol(like)]

            let index = 0;
            return {
                next: () => {
                    return {
                        value: [this[allArr[index]], allArr[index]],
                        done: index++ >= allArr.length
                    }
                }
            }
        }

        for (let [item, key] of obj) {
            console.log(item, key);
        }
    </script>
</body>

</html>